package com.atguigu.spzx.manage.controller;

import com.atguigu.spzx.manage.service.CommunityService;
import com.atguigu.spzx.model.entity.system.Community;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/admin/system/community")
@Slf4j
@Tag(name = "社区管理接口")
public class CommunityController {

    @Autowired
    private CommunityService communityService;

    //社区列表
    @GetMapping("/findNodes")
    public Result findNodes() {
        List<Community> list = communityService.findNodes();
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }
    //分类列表，每次查询一层数据
    // SELECT * FROM category WHERE parent_id=id
    @GetMapping("/findCommunityList/{id}")
    public Result findCommunityList(@PathVariable Long id) {
        List<Community> list = communityService.findCommunityList(id);
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }
    @Operation(summary = "添加社区")
    @PostMapping(value = "/saveCommunity")
    public Result saveCommunity(@RequestBody Community community) {
        log.info("添加的活动:{}",community);
        communityService.saveEvent(community) ;
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }

    //菜单修改
    @PutMapping("/updateCommunity")
    public Result update(@RequestBody Community community) {
        log.info("修改的社区内容:{}",community);
        communityService.update(community);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }
    @Operation(summary = "删除社区")
    @DeleteMapping(value = "/deleteById/{id}")
    public Result deleteById(@PathVariable(value = "id") Long id) {
        communityService.deleteById(id) ;
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }

    //查看一级社区 二级社区
//    @GetMapping("/findCommunityNameByParentId/{id}")
//    public Result findCommunityName(@PathVariable Long id) {
//        List<Community> list = communityService.findCommunityName(id);
//        return Result.build(list, ResultCodeEnum.SUCCESS);
//    }



}
